package cn.lutu.lutu.service.impl;

import cn.lutu.lutu.mapper.ContentMapper;
import cn.lutu.lutu.pojo.dto.ContentCollectDTO;
import cn.lutu.lutu.pojo.dto.ContentPostDTO;
import cn.lutu.lutu.pojo.entity.Content;
import cn.lutu.lutu.pojo.entity.UserProductContent;
import cn.lutu.lutu.security.CustomUserDetails;
import cn.lutu.lutu.service.ContentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Arrays;
import java.util.Date;

@Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    ContentMapper mapper;
    @Override
    public Content insert(ContentPostDTO contentPostDTO,CustomUserDetails cud) {
        Content content = new Content();
        BeanUtils.copyProperties(contentPostDTO,content);
        content.setImgUrl(contentPostDTO.getImgUrl().toString());
        content.setCreateTime(new Date());
        content.setUserId(2L);
        mapper.insert(content);
        return content;
    }

    @Override
    public UserProductContent collect(ContentCollectDTO contentCollectDTO) {
        UserProductContent upc = new UserProductContent();
        BeanUtils.copyProperties(contentCollectDTO,upc);
        mapper.collect(upc);
        return upc;
    }
}
